<template>
    <div class="order-detail-tab flex-a">
        <nut-button type="default" v-if="detail.orderStatus == 0" @click="resetOrder">取消订单</nut-button>
        <nut-button shape="square" v-if="detail.orderStatus == 4" @click="delOrder" type="default">删除订单</nut-button>
        <nut-button type="info" v-if="detail.orderStatus == 0"
            @click="jumpTo('/packageA/pages/confirmPay/index?addressId=' + detail.newBeeMallUserAddressVO.addressId + '&orderId=' + detail.orderNo)">去支付</nut-button>
    </div>
</template>

<script lang="ts">
import Taro, { useRouter } from '@tarojs/taro'
import { reactive, toRefs, onMounted } from 'vue';
import mitt from "./../../../../utils/mitt";
import { removeOrder, cancelOrder } from '../../../../api/index'
export default {
    components: {

    },
    setup() {
        const data = reactive({
            detail: {},
            timer: null as any
        });
        onMounted(() => {
            mitt.on('detail', val => {
                data.detail = val
            })
        });
        const delOrder = () => {
            removeOrder(data.detail.orderId).then(res => {
                if (res.resultCode == 200) {
                    Taro.showToast({
                        title: '删除成功',
                        icon: 'success',
                        duration: 2000
                    })
                    data.timer = setTimeout(function () {
                        Taro.redirectTo({ url: '/pages/orderList/index' })
                    }, 1000)
                }
            })
        }
        const resetOrder = () => {
            cancelOrder(data.detail.orderNo).then(res => {
                if (res.resultCode == 200) {
                    Taro.showToast({
                        title: '取消成功',
                        icon: 'success',
                        duration: 2000
                    })
                    data.detail.orderStatusString = '手动关闭'
                    data.detail.orderStatus = -1
                    data.timer = setTimeout(() => {
                        Taro.redirectTo({ url: '/pages/orderList/index' })
                    }, 1000)
                }
            })
        }
        const jumpTo = (path) => {
            Taro.navigateTo({ url: path })
        }
        return {
            ...toRefs(data), delOrder, jumpTo, resetOrder
        }
    }
};
</script>


<style lang="scss" >
.order-detail-tab {
    position: fixed;
    bottom: 0;
    left: 0;
    background: #fff;
    padding: 20rpx 40rpx;
    box-sizing: border-box;
    width: 100%;
    text-align: right;
    justify-content: flex-end;

    .nut-button {
        width: 200rpx;
        border-radius: 10rpx;
        margin-left: 10rpx;
    }
}
</style>